package sketch.specs;

import java.util.LinkedList;
import java.util.List;

import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.internal.core.dom.NaiveASTFlattener;

public class VariableDeclarationStatementsVisitor extends NaiveASTFlattener {
	
	final List<VariableDeclarationStatement> declared_statements = new LinkedList<VariableDeclarationStatement>();
	
	@Override
	public boolean visit(VariableDeclarationStatement s) {
		if(!this.isDuplicated(s)) {
		    this.declared_statements.add(s);
		}
		return super.visit(s);
	}
	
	public List<VariableDeclarationStatement> getDeclaredStatements() {
		return this.declared_statements;
	}
	
	private boolean isDuplicated(VariableDeclarationStatement s) {
		for(VariableDeclarationStatement exist : this.declared_statements) {
			if(exist.equals(s) && exist.getStartPosition() == s.getStartPosition()) {
				return true;
			}
		}
		return false;
	}
}